from rest_framework.throttling import SimpleRateThrottle


class SMSThrottle(SimpleRateThrottle):
    scope = 'sms'

    def get_cache_key(self, request, view):
        """
        返回什么，就以什么做限制
        :param request:
        :param view:
        :return:
        """
        # cache_format = 'throttle_%(scope)s_%(ident)s'

        telephone = request.query_params.get('telephone')

        return self.cache_format % {'scope': self.scope, 'ident': telephone}